package com.gjy.scala.funtion

object FilterUseage {
  def main(args: Array[String]): Unit = {

    //过滤1到10的偶数
    val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    val evenNumbers = numbers.filter(_ % 2 == 0)
    println(evenNumbers)

    //过滤字符串数组中长度大于5的
    val words = List("apple", "banana", "cherry", "date", "elderberry")
    val longWords = words.filter(_.length > 5)
    println(longWords)

    //过滤数组中大于0的
    val array = Array(-2, -1, 0, 1, 2)
    val positiveNumbers = array.filter(_ > 0)
    println(positiveNumbers.mkString(", ")) // 输出: 1, 2

    // 过滤Map中值大于10的
    val map = Map("a" -> 1, "b" -> 2, "c" -> 3, "d" -> 11, "e" -> 12)
    val filteredMap = map.filter { case (key, value) => value > 10 }
    println(filteredMap) // 输出: Map(d -> 11, e -> 12)

    // 过滤List中元组中第二个元素大于10的
    val tuples = List((1, 2), (3, 4), (5, 6), (7, 8), (9, 10))
    val filteredTuples = tuples.filter { case (_, value) => value % 2 == 0 }
    println(filteredTuples) // 输出: List((1, 2), (3, 4), (5, 6), (7, 8), (9, 10))

  }

}
